package com.px.user.mapper;


import com.px.user.entity.ChargeChannel;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface ChargeChannelMapper {

    @Options(useGeneratedKeys = true, keyProperty = "id", keyColumn = "id")
    @Insert("insert into charge_channel (name,url,value,start,end,disabled,channelNo,paymentType,isfixedAmount,fixedAmount) values (#{name},#{url},#{value},#{start},#{end},#{disabled},#{channelNo},#{paymentType},#{isfixedAmount},#{fixedAmount})")
    void insert(ChargeChannel chargeChannel);

    @Update({"<script>",
            "update charge_channel",
            " <set>",
            "  <if test='name != null'>name=#{name},</if>",
            "  <if test='url != null'>url=#{url},</if>",
            "  <if test='value != null'>value=#{value},</if>",
            "  <if test='start != null'>start=#{start},</if>",
            "  <if test='end != null'>end=#{end},</if>",
            "  <if test='disabled != null'>disabled=#{disabled}</if>",
            "  <if test='channelNo != null'>channelNo=#{channelNo}</if>",
            "  <if test='paymentType != null'>paymentType=#{paymentType}</if>",
            "  <if test='isfixedAmount != null'>disabled=#{isfixedAmount}</if>",
            "  <if test='fixedAmount != null'>fixedAmount=#{fixedAmount}</if>",
            " </set>",
            "where id=#{id}",
            "</script>"})
    void update(ChargeChannel chargeChannel);

    @Delete("delete from user where id =#{id}")
    void delete(Long id);

    @Select({"<script>",
            "select * from charge_channel",
            "<where>",
            " <if test='id != null'>and id = #{id}</if>",
            " <if test='name != null'>and name like #{name}</if>",
            " <if test='url != null'>and url = #{url}</if>",
            " <if test='value != null'>and value = #{value}</if>",
            " <if test='start != null'>and start = #{start}</if>",
            " <if test='end != null'>and end = #{end}</if>",
            " <if test='disabled != null'>and disabled = #{disabled}</if>",
            " <if test='qstart != null'>and createTime >= #{qstart}</if>",
            " <if test='qend != null'>and createTime <![CDATA[<=]]> #{qend}</if>",
            "</where>",
            "order by ${orderField} desc limit #{startIndex},#{limit}",
            "</script>"})
    List<ChargeChannel> paging(ChargeChannel chargeChannel);


    @Select({"<script>",
            "select count(1) from charge_channel",
            "<where>",
            " <if test='id != null'>and id = #{id}</if>",
            " <if test='name != null'>and name like #{name}</if>",
            " <if test='url != null'>and url = #{url}</if>",
            " <if test='value != null'>and value = #{value}</if>",
            " <if test='start != null'>and start = #{start}</if>",
            " <if test='end != null'>and end = #{end}</if>",
            " <if test='disabled != null'>and disabled = #{disabled}</if>",
            " <if test='qstart != null'>and createTime >= #{qstart}</if>",
            " <if test='qend != null'>and createTime <![CDATA[<=]]> #{qend}</if>",
            "</where>",
            "</script>"})
    Integer pagingCount(ChargeChannel chargeChannel);
}
